"do.vol.modeling"=function(test,test.data.vector,phase1fits,x,dates,automatic=T,plot=T,useGPH=F){
	#shifted.multivar.test.data.vector = shift.df.multi(test.data.vector,test,independent.variables)
	#response = as.matrix(subset(shifted.multivar.test.data.vector, select = test))
      response = test.data.vector
	if(automatic){
		resid.model=auto.arima(x)
		mean.equation.params = length(resid.model$coef)
		model.check.temp = model.check(resid.model,mean.equation.params,0,12)
		d=0
	}else{
		resid.model.temp=auto.model(current.test.name=test, percentage=1, cut.off=FALSE, interp=FALSE, data=x, useGPH=useGPH)
		resid.model=resid.model.temp$model
		d=resid.model.temp$d
		model.check.temp = resid.model.temp$model.check
	}
	if ((class(resid.model)) == "fGARCH"){
            	res2 	= as.numeric(resid.model@residuals)
			sres2 = as.numeric(resid.model@residuals)/as.numeric(resid.model@sigma.t);			#	  
			fit2 = as.numeric(resid.model@fitted)
            }else{
               	res2 	= as.numeric(resid.model$residuals);
			sres2 = res2
			fit2 = x - res2
		}

	adf.test = adf.urca.test(res2)
	if(plot){
	
	
		fit1 = phase1fits
		
		residuals1 = x
		residuals2 = res2
		actual = response		
		regression.dataframe = as.data.frame(cbind(actual, fit1+fit2,residuals2))
		names(regression.dataframe) = c(test,"Phase 1/2 Fit","Res1/2")
		plot.actual.fitted(regression.dataframe,test,dates,sreturn=TRUE,same.scale=T)
		eacf(x)
	}
	structure(list(model=resid.model,d=d,model.check=model.check.temp, adftest = adf.test,res=res2,sres = sres2))
}
